package com.nikmesoft.android.ebox.adapters;

import java.util.List;
import com.nikmesoft.android.ebox.R;
import com.nikmesoft.android.ebox.models.Item;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemAdapter extends ArrayAdapter<Item> {

	private int resourceID;

	public ItemAdapter(Context context, int resourceID, List<Item> objects) {
		super(context, resourceID, objects);
		this.resourceID = resourceID;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Item item = getItem(position);
		View row = convertView;
		if (row == null) {
			LayoutInflater inflater;
			inflater = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(this.resourceID, null);
		} else {
			row = convertView;
		}

		TextView tvNameItem = (TextView) row.findViewById(R.id.tvNameItem);

		ImageView imvAvatarItem = (ImageView) row
				.findViewById(R.id.imvAvatarItem);
		if (item.getType() == Item.Type.Folder) {
			imvAvatarItem.setImageResource(R.drawable.icon1);
		} else if (item.getType() == Item.Type.Photo) {
			imvAvatarItem.setImageResource(R.drawable.icon2);
		} else if (item.getType() == Item.Type.Video) {
			imvAvatarItem.setImageResource(R.drawable.icon3);
		}

		tvNameItem.setText(item.getName());
		return row;

	}

}
